package com.wabacus.system;

import java.util.Map;

import javax.servlet.*;
import javax.servlet.http.*;


public class ServletContextSelfListener extends HttpServlet implements
		ServletContextListener {

	public ServletContextSelfListener() {
	}

	public void destroy() {
		context = null;
	}

	public void contextInitialized(ServletContextEvent event) {
		System.out.println("系统启动时调用*************************");
		context = event.getServletContext();
		String path = context.getRealPath("WEB-INF") + "\\";
		//new LicenceEntity(path);
		// 认证成功写一个全局变量 后期可以进行判断
		context.setAttribute("licenceRegister", licenceInfo());
	}

	public String licenceInfo() {
		Map<String, String> map = System.getenv();
		String userName = map.get("USERNAME");
		String computerName = map.get("COMPUTERNAME");
		String userDomain = System.getProperty("os.name");
		com.system.cipher.MD5 md5 = new com.system.cipher.MD5();
		String key=md5.getMD5ofStr(userName+ computerName + userDomain);
		return key;
	}

	public void contextDestroyed(ServletContextEvent event) {
		System.out.print("系统关闭时调用*************************");
		destroy();
	}

	private static final long serialVersionUID = 0x9edcf962b6a825cL;
	private ServletContext context;

}
